﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;
namespace final.wuc
{
    public partial class wucdangki : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void imgsubmit_Click(object sender, ImageClickEventArgs e)
        {
            UserBUS userbus = new UserBUS();
            TUSER user = userbus.Getall().SingleOrDefault(n => n.Username == txtsignupuser.Text);
            

            if (user != null)
            {
                lblerror.Text = "Username has exists";
                txtsignupuser.Focus();
            }
            else
            {
                user = new TUSER();
                user.Username = txtsignupuser.Text;
                user.Pass = txtsignuppass.Text;
                user.FullName = txtfullname.Text;
                user.Email = txtemail.Text;
                user.DoB = System.DateTime.Parse(txtdob.Text);
                user.Phone = txtphone.Text;
                user.Sex = rBtnSex.SelectedValue.ToString();

                if (userbus.adduser(user) == true)
                {
                    user = userbus.checkLogin(txtsignupuser.Text, txtsignuppass.Text);
                    Session["URLHienTai"] = Request.Url.ToString();
                    Session["isLogin"] = true;
                    Session["user"] = user;
                    Response.Redirect("~/test.aspx");

                }
            }
        }
    }
}